home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Widget Wizard.dir / WidgtBehaviors_72_physics.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  2.0 KB  |  59 lines

  1. property friction, xpos, ypos, oldxpos, oldypos, xvel, yvel, mass, xacc, yacc, enable
  2.  
  3. on getPropertyDescriptionList
  4.   set D to [:]
  5.   addProp(D, #friction, [#default: 0.80000000000000004, #format: #float, #comment: "Friction:", #range: [#min: 0.0, #max: 1.0]])
  6.   addProp(D, #xacc, [#default: 0.0, #format: #float, #comment: "Accel X Magnitude:"])
  7.   addProp(D, #yacc, [#default: 0.0, #format: #float, #comment: "Accel Y Magnitude:"])
  8.   addProp(D, #xvel, [#default: 0.0, #format: #float, #comment: "Velocity X Magnitude:"])
  9.   addProp(D, #yvel, [#default: 0.0, #format: #float, #comment: "Velocity Y Magnitude:"])
  10.   return D
  11. end
  12.  
  13. on beginSprite me
  14.   set the xpos of me to the locH of sprite the spriteNum of me
  15.   set the ypos of me to the locV of sprite the spriteNum of me
  16.   set the oldxpos of me to the xpos of me
  17.   set the oldypos of me to the ypos of me
  18.   set the mass of me to 0.0
  19.   set the enable of me to 0
  20. end
  21.  
  22. on move me
  23.   if the enable of me then
  24.     set the xvel of me to the xvel of me + the xacc of me
  25.     set the yvel of me to the yvel of me + the yacc of me
  26.     set the xvel of me to the xvel of me * the friction of me
  27.     set the yvel of me to the yvel of me * the friction of me
  28.     set the xpos of me to the xpos of me + the xvel of me
  29.     set the ypos of me to the ypos of me + the yvel of me
  30.     set the locH of sprite the spriteNum of me to the xpos of me
  31.     set the locV of sprite the spriteNum of me to the ypos of me
  32.   end if
  33. end
  34.  
  35. on exitFrame me
  36.   if the enable of me then
  37.     move(me)
  38.   end if
  39. end
  40.  
  41. on start me
  42.   set the enable of me to 0
  43. end
  44.  
  45. on stop me
  46.   set the enable of me to 0
  47. end
  48.  
  49. on setVelocity me
  50.   set currx to the locH of sprite the spriteNum of me
  51.   set curry to the locV of sprite the spriteNum of me
  52.   set the xvel of me to currx - the oldxpos of me
  53.   set the yvel of me to curry - the oldypos of me
  54.   set the oldxpos of me to currx
  55.   set the oldypos of me to curry
  56.   set the xpos of me to the locH of sprite the spriteNum of me
  57.   set the ypos of me to the locV of sprite the spriteNum of me
  58. end
  59.